package com.cskaoyan.jdbc.crud;

import com.cskaoyan.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 创建日期: 2022/11/16 17:38
 *
 * @author ciggar
 */
public class ExecuteDemo {
    public static void main(String[] args) throws SQLException {

        // 1. 获取连接
        Connection connection = JDBCUtils.getConnection();

        // 2. 获取statement
        Statement statement = connection.createStatement();

        // 3. 执行SQL语句
        boolean ret = statement.execute("select * from stu where id = 3001");

        System.out.println("ret:" + ret);

        ResultSet resultSet = statement.getResultSet();

        while (resultSet.next()) {
            String name = resultSet.getString("name");
            int id = resultSet.getInt("id");

            System.out.println("name:" + name);
            System.out.println("id:" + id);
        }

        resultSet.close();
        statement.close();
        connection.close();
    }
}
